package Bacterias;

import com.game.ThauanFramework.TimeManager;

import android.util.Log;

public class DeathOpaticyRunnable implements Runnable {

	private final String TAG = "Death Opacity Runnable";
	private final int interval = 10;
	public boolean isAlive = true;

	private float lifeTime = 4;
	private double cronometro = 0;

	private PostDeathEffect pos;

	public void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}

	public DeathOpaticyRunnable(PostDeathEffect pos, float lifeTime) {
		this.pos = pos;
		this.lifeTime = lifeTime;
		Thread thread = new Thread(this);
		thread.start();
	}

	@Override
	public void run() {
		while (isAlive) {

			try {
				Thread.sleep(interval);
			} catch (InterruptedException e) {
				Log.e(TAG, "Erro na Runnable de For Shake");
				e.printStackTrace();
			}

			this.cronometro += TimeManager.getInstance().getDeltaTime();
			if (this.cronometro >= this.lifeTime) {
				this.setAlive(false);
			} else {
				this.pos.opacity = (int) ((this.lifeTime - this.cronometro)*(100/this.lifeTime));
			}
		}
	}
}
